<script>
    function goBack() {
	window.location.href = "?modul=events&action=events_list";
    }
</script>
<?php

function V_Add_Events($arrayData, $mode) {
    include("../fckeditor/fckeditor.php");
    $ulr = "?" . MODUL . "=events&" . ACTION . "=" . $mode;
    if ($mode == 'Edit_events') {
	$strLable = "Cập nhật sự kiện";
	$strButton = "Cập nhật";
    } else if ($mode == 'add_events') {
	$strLable = "Thêm mới sự kiện";
	$strButton = "Thêm mới";
    }
    ?>
    <h3><?= $strLable ?></h3>
    <form enctype="multipart/form-data" action="<?= $ulr ?>" method="post" name="frm" onSubmit="return validateForm();">
        <input type="hidden" name="id" id="id" value="<?= $arrayData['id']; ?>"/>
        <table width="950px" cellpadding="5" border="1">
    	<tr style="background-color: #99CCFF">
    	    <th colspan="2">Thông tin sự kiện</th>
    	</tr>
    	<tr>
    	    <td width="200px"><strong>Chọn loại sự kiện</strong></td>
    	    <td>
    		<select name="event_type">
    		    <option value="0">---ROOT---</option>
			<? events_type(0, 0, $arrayData['event_type']); ?>
    		</select>
    	    </td>
    	</tr>
    	<tr>
    	    <td><strong>Hiển thị trang chủ</strong></td>
    	    <td>
		    <?
		    if ($arrayData['show_home'] == '1') {
			$selected0 = "";
			$selected1 = "checked";
		    }
		    if ($arrayData['show_home'] == '0') {
			$selected0 = "checked";
			$selected1 = "";
		    }
		    ?>
    		<input <?= $selected1 ?> type="radio" name="show_home" value="1"/>Có
    		<input <?= $selected0 ?> type="radio" name="show_home" value="0"/>Không
    	    </td>
    	</tr>
    	<tr>
    	    <td><strong>Tên sự kiện</strong></td>
    	    <td>
    		<input style="width: 600px" type="text" name="title_event" id="title_event" value="<?= $arrayData['title_event']; ?>"/>
    	    </td>
    	</tr>
    	<tr>
    	    <td><strong>Tác Giả</strong></td>
    	    <td>
    		<input style="width: 200px" type="text" name="author_event" id="author_event" value="<?= $arrayData['author_event']; ?>"/>
    	    </td>
    	</tr>
    	<tr>
    	    <td><strong>Ngày viết</strong></td>
    	    <td>
    		<input style="width: 200px" type="text" name="date_event" id="date_event" value="<?= date('d-m-Y', strtotime($arrayData['date_event'])); ?>"/>
    	    </td>
    	</tr>
	    <?
	    if ($mode == 'Edit_events') {
		if ($arrayData['image_event'] != "") {
		    ?>
	    	<tr>
	    	    <td><strong>Ảnh</strong></td>
	    	    <td>
	    		<img width="300px" src="<?= DIR_IMG_EVENT . $arrayData['image_event'] ?>"/><br/>
	    <?= $arrayData['image_event'] ?>
	    	    </td>
	    	</tr>
		<? }
	    }
	    ?>
    	<tr>
    	    <td><strong>Ảnh Sự Kiện</strong></td>
    	    <td>
    		<input type="file" name="image_event" id="image_event" value="<?= $arrayData['image_event'] ?>"/>
    	    </td>
    	</tr>
    	<tr>
    	    <td><strong>Phần Mở Đầu</strong></td>
    	    <td>
    		<textarea style="width: 450px; height: 100px" name="header_event" id="header_event"><?= $arrayData['header_event']; ?></textarea>
    	    </td>
    	</tr>
    	<tr>
    	    <td><strong>Nội Dung Sự Kiện</strong></td>
    	    <td>
        <!--    		<textarea style="width: 400px; height: 150px" name="events_info" id="events_info"><?= $arrayData['events_info']; ?></textarea>-->
		    <?php
		    // Lay ve duong dan chinh cua server.
		    $sBasePath = $_SERVER['PHP_SELF'];

		    // Lay ve thu muc goc cho den _sample.
		    $sBasePath = substr($sBasePath, 0, strpos($sBasePath, "run"));
		    //echo "sBasePath = $sBasePath";
		    $sBasePath = $sBasePath . "fckeditor/";
		    $oFCKeditor = new FCKeditor('content_event');
		    $oFCKeditor->BasePath = $sBasePath;
		    $oFCKeditor->Width = '100%';
		    $oFCKeditor->Height = '400';
		    $oFCKeditor->Value = $arrayData["content_event"];
		    $oFCKeditor->Create();
		    ?>
    	    </td>
    	</tr>
    	<tr>
    	    <td colspan="2">
    		<div style="float: right">
    		    <input type="reset" name="reset"  value="Nhập lại"/>
    		    <input type="submit" name="Submit" value="<?= $strButton ?>"/>
    		    <input type="button" name="Back" value="Quay lại" onclick="goBack();"/>
    		</div>
    	    </td>
    	</tr>
        </table>
    </form>
    <?
}

function events_type($parent_id, $level, $id_nhom) {
    global $db;
    $objEvents = new MD_Event($db);
    $where = "parent_id = '$parent_id'";
    $order = "";
    $limit = "";
    $array = $objEvents->get_events_type_by_Where($where, $order, $limit);
    foreach ($array as $value) {
	$id = $value['id'];
	$selected = "";
	if ($id_nhom == $id) {
	    $selected = "Selected";
	}
	echo '<option ' . $selected . ' value="' . $id . '">' . str_repeat('- - ', $level) . $value['event_type_name'] . '</option>';
	events_type($id, $level + 1, $id_nhom);
    }
}
?>
